package com.anzhen.interview.singleton;

/**
 * 懒汉
 * Created by zhenan on 2017-3-20.
 */
public class Singleton_Lazy {
    // 静态实例变量加上volatile
    private static volatile Singleton_Lazy instance;

    // 私有化构造函数
    private Singleton_Lazy() {

    }

    // 双重检查锁
    public static Singleton_Lazy getInstance() {
        if (instance == null) {
            synchronized(Singleton_Lazy.class){
                if(instance == null){
                    instance = new Singleton_Lazy();
                }
            }
        }
        return instance;
    }
}
